<template>
    <div>
        <h3>房号添加</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房号名称</td>
                    <td>
                        <input type="text" v-model="queryadd.HouseName">
                    </td>
                </tr>
                <tr>
                    <td>门店</td>
                    <td>
                        <select v-model="queryadd.ShopId">
                            <option value="">请选择</option>
                            <option :value="item.Id" v-for="item in shop.list">{{item.ShopName}}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>房型</td>
                    <td>
                        <select v-model="queryadd.HouseTypeId">
                            <option value="">请选择</option>
                            <option :value="item.Id" v-for="item in house.list">{{item.HouseTypeName}}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>房态</td>
                    <td>
                        <select v-model="queryadd.HouseState">
                            <option value="">请选择</option>
                            <option :value="1">空闲</option>
                            <option :value="2">已入住</option>
                            <option :value="3">已预约</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" @click="add">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import{ref,reactive,onMounted} from 'vue'
import {useRouter,useRoute} from 'vue-router'
import axios from 'axios';
import moment from 'moment';

const router=useRouter();
const route=useRoute();


onMounted(()=>{
    showshop();
    showHouse();
})

const queryadd=reactive({
 
  "HouseName": "",
  "ShopId": '',
  "HouseTypeId": '',
  "HouseState": '',
})
const add=()=>{
    if(queryadd.HouseName==""){
        alert("房间号不能为空");
        return;
    }
    if(queryadd.ShopId==""){
        alert("门店不能为空");
        return;
    }
    if(queryadd.HouseTypeId==""){
        alert("房型不能为空");
        return;
    }
    if(queryadd.HouseState==""){
        alert("房态不能为空");
        return;
    }
    axios({
        method:'post',
        url:'/api/House/HouseNoAdd',
        data:queryadd,
    })
    .then(res=>{
        console.log(res);

        if(res.data>0){
            alert("添加成功");
        }
        else{
            alert("添加失败")
        }
    })
    .catch(err=>{
        console.log(err);
    })
}
const shop:any=reactive({
    list:[],
})
const showshop=()=>{
    axios({
        method:'get',
        url:'/api/Shop/GetShopList',
        params:{
            pageIndex:1,
            pageSize:1000,
        }
    })
    .then(res=>{
        console.log(res);
        shop.list=res.data.list     
    })
    .catch(err=>{
        console.log(err);
    })
}
const house:any=reactive({
    list:[],
})
const showHouse=()=>{
    axios({
        method:'get',
        url:'/api/House/GetHouseTypeList',
        params:{
            pageIndex:1,
            pageSize:1000,
        }   
    })
    .then(res=>{
        console.log(res);
        house.list=res.data.list
       
    })
    .catch(err=>{
        console.log(err);
    })
}
    

</script>

<style scoped>

</style>